from selenium import webdriver
from selenium.webdriver.common.by import By
import pywinauto
import time

driver = webdriver.Chrome()
driver.maximize_window()

driver.get("https://jianwai.youdao.com/")
# 切换表单
driver.switch_to.frame(driver.find_element(By.XPATH, "//iframe[@frameborder='0']"))
driver.find_element(By.XPATH, "//input[@name='email']").send_keys("974381044@qq.com")
driver.find_element(By.XPATH, "//input[@name='password']").send_keys("zytc@12310120")
driver.find_element(By.XPATH, "//a[@id='dologin']").click()
time.sleep(2)

driver.find_element(By.XPATH, "//div[text()='新建项目']").click()
driver.find_element(By.XPATH, "//div[text()='图片翻译']").click()
time.sleep(2)

# # input标签使用send_keys实现文件上传
# driver.find_element(By.XPATH, "//input[@type='file']").send_keys(r'C:\TT\习知\课件\我的课件\1624958787.png')

# 非input标签或者不使用send_keys，实现文件上传
driver.find_element(By.XPATH, "//input[@type='file']").click()
app = pywinauto.Desktop()
win = app['打开']
win['Edit'].type_keys(r'C:\TT\习知\课件\我的课件\1624958787.png')
time.sleep(2)
win['Button'].click()

time.sleep(5)
driver.quit()
